﻿using System.Diagnostics.CodeAnalysis;

namespace zijian666.AnyExtensions;

/// <summary>
/// 布尔型扩展
/// </summary>
public static class BooleanExtensions
{
    /// <summary>
    /// 取反
    /// </summary>
    public static bool Not(this bool b) => !b;
    /// <summary>
    /// 有值 且为 true
    /// </summary>
    public static bool IsTrue(this bool? b) => b.HasValue && b.Value;
    /// <summary>
    /// 有值 且为 false
    /// </summary>
    public static bool IsFalse(this bool? b) => b.HasValue && !b.Value;
    /// <summary>
    /// 值为 null 或 true
    /// </summary>
    public static bool IsNullOrTrue([NotNullWhen(false)] this bool? b) => b is null || b.Value;
    /// <summary>
    /// 值为 null 或 false
    /// </summary>
    public static bool IsNullOrFalse([NotNullWhen(false)] this bool? b) => b is null || !b.Value;
}
